﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class admin_edconsultinglang : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        SqlCommand mySqlSelect = new SqlCommand("select * from Consulting_lang where id = @id and lang = @lang", cn);
        mySqlSelect.CommandType = CommandType.Text;
        SqlParameter paramid = new SqlParameter("@id", SqlDbType.BigInt);
        paramid.Value = Request.Params["id"];
        mySqlSelect.Parameters.Add(paramid);
        SqlParameter paramlg = new SqlParameter("@lang", SqlDbType.NVarChar, 2);
        paramlg.Value = Request.Params["lang"];
        mySqlSelect.Parameters.Add(paramlg);
        try
        {
            SqlDataReader rd = mySqlSelect.ExecuteReader();
            if (rd.HasRows)
            {
                rd.Read();
                menu.Text = rd.GetSqlString(2).ToString();
                title.Text = rd.GetSqlString(3).ToString();
            }
            rd.Close();
            cn.Close();
        }
        catch (Exception ex)
        {
            cn.Close();
            Console.WriteLine("Loi setValueFromDatabaseToForm : " + ex);
        }
    }

    protected void addbt_Click(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        SqlCommand mySqlSelect = new SqlCommand("update Consulting_lang set menu = @menu, title= @title where id = @id and lang = @lang", cn);
        mySqlSelect.CommandType = CommandType.Text;
        SqlParameter paramid = new SqlParameter("@id", SqlDbType.BigInt);
        paramid.Value = Request.Params["id"];
        mySqlSelect.Parameters.Add(paramid);
        SqlParameter paramlg = new SqlParameter("@lang", SqlDbType.NVarChar, 2);
        paramlg.Value = Request.Params["lang"];
        mySqlSelect.Parameters.Add(paramlg);

        SqlParameter me = new SqlParameter("@menu", SqlDbType.NVarChar, 50);
        me.Value = menu.Text;

        SqlParameter tit = new SqlParameter("@title", SqlDbType.NVarChar, 100);
        tit.Value = title.Text;

        mySqlSelect.Parameters.Add(me);
        mySqlSelect.Parameters.Add(tit);
        mySqlSelect.ExecuteNonQuery();
        cn.Close();
        info.Text = "Cập nhật dữ liệu thành công";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?page=qlconsultinglang&id=" + Request.Params["id"]);
    }
}